-
-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(index): escape double quotes correctly (options.interpolate
)
#154
fix(index): escape double quotes correctly (options.interpolate
)
#154
Conversation
Codecov Report
@@ Coverage Diff @@
## master #154 +/- ##
==========================================
+ Coverage 96.96% 97.02% +0.06%
==========================================
Files 2 2
Lines 99 101 +2
Branches 20 20
==========================================
+ Hits 96 98 +2
Misses 3 3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-ciniawsky - Ship it if you are good with it
@@ -129,6 +129,9 @@ module.exports = function(content) { | |||
} | |||
|
|||
if(config.interpolate && config.interpolate !== 'require') { | |||
// Double escape quotes so that they are not unescaped completely in the template string | |||
content = content.replace(/\\"/g, "\\\\\""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\\\\\('|")
(5) => \\\\('|")
(4) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand.
The two regexes could be combined into one .replace(/\\("|')/g, "\\\\$1")
or what do you mean?
@@ -71,6 +71,11 @@ describe("loader", function() { | |||
'module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p><!-- comment --><img src=\" + require("./image.png") + \" />";' | |||
); | |||
}); | |||
it("should preserve escaped quotes", function() { | |||
loader.call({}, '<script>{"json": "with \\"quotes\\" in value"}</script>').should.be.eql( | |||
'module.exports = "<script>{\\\"json\\\": \\\"with \\\\\\\"quotes\\\\\\\" in value\\\"}</script>";' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only occurs for { key: "bla \"blub\" bla" }
, but doesn't on { key: "bla 'blub' bla" }
right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Michael,
sorry for the late reply, but yes: that is correct. I've updated my minimal test case with two more examples: https://github.com/benurb/html-loader-escape-bug
options.interpolate
)
Is there still anything I can do? @michael-ciniawsky |
@benurb - Everyone is a bit buried getting ready for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benurb Thx && Sry for the delay
options.interpolate
)options.interpolate
)
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behavior? (You can also link to an open issue here)
Currently escaped quotes in inline scripts are unescaped when interpolation is enabled. You can find a minimal test case here: https://github.com/benurb/html-loader-escape-bug
What is the new behavior?
interpolate=true behaves like disabled interpolation and quotes are still escaped.
Does this PR introduce a breaking change?
The documentation states no difference between interpolate=true and false regarding the handling of escaped quotes.
If this PR contains a breaking change, please describe the following...
Other information:
This solution is very hacky, but I couldn't find a cleaner one 😞
Without these changes the second of the two added tests fails.
This PR might also be a fix for #153 though I don't use angular and haven't tested it.